// Created by WXX on 2021/9/10 9:19
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * 执行用时：116 ms, 在所有 C++ 提交中击败了91.64%的用户
 * 内存消耗：72.6 MB, 在所有 C++ 提交中击败了63.50%的用户
 */
class Solution {
public:
    typedef long long LL;
    int chalkReplacer(vector<int>& chalk, int k) {
        LL sum = 0;
        for (auto x : chalk) sum += x;
        k %= sum;
        for (int i = 0; i < chalk.size(); i++) {
            if (k < chalk[i]) return i;
            k -= chalk[i];
        }
        return -1;  // 一定不会被执行
    }
};

int main() {

    vector<int> chalk = {5, 1, 5};
    cout << Solution().chalkReplacer(chalk, 22) << endl;  // 0

    return 0;
}
